package com.ruoyi.common.enums.business;


import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum TaskRewardTypeEnum {

    POINTS(1, "积分"),

    PRODUCT(2, "产品"),

    PRODUCT_POINTS(3, "产品与积分"),


    ;

    private final Integer status;

    private final String desc;


    private static final Map<Integer, TaskRewardTypeEnum> ENUM_MAP;

    static {
        TaskRewardTypeEnum[] values = values();
        Map<Integer, TaskRewardTypeEnum> enToCn = new HashMap<>(values.length);
        for (TaskRewardTypeEnum value : values) {
            enToCn.put(value.getStatus(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static TaskRewardTypeEnum getEnumByType(Integer status) {
        TaskRewardTypeEnum taskRewardTypeEnum = ENUM_MAP.get(status);
        if (ObjectUtil.isEmpty(taskRewardTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return taskRewardTypeEnum;
    }


}
